package com.cqndt.device.data.controller;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.utils.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author qingqinchao
 */
@RestController
public class testController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping(value = "test")
    public void setMessage(){
        Map<String,Object> map = new HashMap(16);
        map.put("name","ssddgh");
        map.put("age",12);
        byte[] serialize = SerializationUtils.serialize(map);
        rabbitTemplate.convertAndSend("test",serialize);
    }

//    @RabbitListener(queuesToDeclare = {@Queue("test")})
//    public void getMessage(Message message) {
//        System.out.println(message);
//        byte[] body = message.getBody();
//        Map map = (Map) org.apache.commons.lang.SerializationUtils.deserialize(body);
//        System.out.println(map);
//    }
}
